package com.shengl.app.util;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PageForResultSet {

	public static List transactResultSet(ResultSet rs,  RowMapper rowMapper) throws SQLException{
		List item = new ArrayList();
		int rowNum = 0;
    	while (rs.next()) {
    		item.add(rowMapper.mapRow(rs, rowNum++));
    	}
		return item;
	}

	public static List transactResultSet(Page page, ResultSet rs, RowMapper rowMapper) throws SQLException{
		int recordCount = 0;
		List item = new ArrayList();
		int rowNum = 0;
    	while (rs.next()) {
    		if(rowNum < Constants.PAGE_SIZE + page.getStartRow()) {
    			if (rowNum >= page.getStartRow()) item.add(rowMapper.mapRow(rs, rs.getRow()));
    		}
    		rowNum++;
    		recordCount = rs.getRow();
    	}
    	page.setMaxPage(recordCount - 1);
    	
		return item;
	}
}
